Ext.define("XTFrame.view.system.SQLManager",{
	extend: 'Ext.grid.Panel',
	region: 'center',
	frame: true,
	autoScroll: true,
	enableKeyNav: true,//按键操作
//	forceFit: true,//自动填充panel空白处
	columns: [ Ext.create("Ext.grid.RowNumberer", {width:32}),
				{width: 80, text: 'SQL类型', dataIndex: 'sqltype', sortable: true, renderer: function(value) {
					if(value == 1){
						return "mysql";
					} else if(value == 2){
						return "oracle";
					} else {
						return "other";
					}
				}},  
				{width: 220, text: 'SQL编号', dataIndex: 'sqlid', sortable: true},//用于锁定列：, locked: true}, 
				{width: 160, text: 'SQL名称', dataIndex: 'sqlname'}, 
				{width: 120, text: '模型', dataIndex: 'sqlmode'}, 
				{width: 120, text: '验证规则', dataIndex: 'dataverify'}, 
				{width: 60, text: '序号', dataIndex: 'orderno', sortable: true}, 
				{width: 160, text: '备注', dataIndex: 'remark'} ],
//	tbar: {
//		xtype: 'container',
//		layout: 'anchor',
//		defaults: {anchor: '0'},
//		defaultType: 'toolbar',
//		items: [{
//			items: [{xtype: 'button', text: '添加', action: 'gridAdd', iconCls: 'icon-add'}] // toolbar 1
//		}, {
//			items: [{xtype: 'button', text: '删除', action: 'gridDelete', iconCls: 'icon-delete'}] // toolbar 2
//		}]
//	},
	tbar: [ {xtype: 'button', text: '添加', action: 'gridAdd', iconCls: 'icon-add'},
			{xtype: 'button', text: '删除', action: 'gridDelete', iconCls: 'icon-delete'},
			{xtype: 'button', text: '修改', action: 'gridEdit', iconCls: 'icon-edit'},
			{xtype: 'button', text: '查询', action: 'gridSearch', iconCls: 'icon-search'} ],
	initComponent:function(){
		var me = this;
		Ext.create('XTFrame.store.SQL', {storeId: 's_sql',
			listeners:{
				beforeload: function(store, options){
			        var new_params = {
						iFunc: ajaxUtil.FUNC_PAGING,
						strData: Ext.JSON.encode({totalSqlValue: ["xtframe_sql_manage_1", me.sqlid, me.sqltype],
							querySqlValue: ["xtframe_sql_manage_2", options.start, options.limit, me.sqlid, me.sqltype]})
					};
			        Ext.apply(store.proxy.extraParams, new_params);
			    },
			    load: function(store, records, successful){
			    	if(successful){
			    		ajaxUtil.isLogin(store.proxy.reader.jsonData);
			    	}
			    }
			}
		});
		Ext.apply(this,{
			store: Ext.data.StoreManager.lookup('s_sql'),
			selType: 'checkboxmodel',
			multiSelect: true,
			sqlid: '',
			sqltype: 0,
			editWindow: 'XTFrame.view.system.SQLEditWindow',
			editWinId: 'sqlEditWindow',
			searchWindow: 'XTFrame.view.system.SQLSearchWindow',
			searchWinId: 'sqlSearchWindow',
			addSql: 'xtframe_sql_manage_4',
			addValues: ['sqlid', 'sqltype', 'sqlname', 'sqlmode', 'dataverify', 'orderno', 'remark'],
			editSql: 'xtframe_sql_manage_5',
			editValues: ['sqlid', 'sqltype', 'sqlname', 'sqlmode', 'dataverify', 'orderno', 'remark'],
			deleteSql: 'xtframe_sql_manage_3',
			deleteValues: ['sqlid', 'sqltype'],
			searchValues: ['sqlid', 'sqltype'],
			dockedItems: [{
				xtype: 'pagingtoolbar',
				dock: 'bottom',
				displayInfo: true,
				store: Ext.data.StoreManager.lookup('s_sql')
			}],
			listeners: {	//解决滚动条卡住问题
				scrollershow: function(scroller) {
//					var g = this.up('gridpanel');
//					if (g) {
//						g.invalidateScroller();
//					}
					if (scroller && scroller.scrollEl) {
						scroller.clearManagedListeners();
						scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
					}
				}
			}
		});
		this.callParent(arguments);
	}
});